<?php

abstract class Model extends CActiveRecord
{

    public $findByPk;
    private $model;
    private $class;

    public function init()
    {
        $this->model = get_class($this);
        $this->class = strtolower($this->model);
    }

    public function getNextId()
    {
        $row = $this->getDbConnection()->createCommand("SHOW TABLE STATUS LIKE '" . $this->tableName() . "'")->queryRow();
        return $row["Auto_increment"];
    }

    public static function getRandom($length)
    {
        $string = '';
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $size = strlen($chars);
        for ($i = 0; $i < $length; $i++) {
            $string .= $chars[rand(0, $size - 1)];
        }
        return $string;
    }

    public function getYear(){
        return date("Y", time());
    }
}